<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
use think\Session;
use think\Request;
class Login extends Controller{
public function login()
{
    //验证验证码是否正确
    //验证用户名密码是否正确
    //验证用户是否禁用
    //判断用户角色进入不同页面

    $data = input("post."); //form表单用post传
    $validate = \think\Loader::validate('User');
    if (!$validate->check($data)) {
        $this->error($validate->getError());
    }
    //验证用户名密码必填等（前台可能会被改动）（用户名密码必填，用户名长度10）

    //dump($data);
    $data = [
        'adminname' => input('adminname'),
        'password' => md5(input('password'))
    ];
    $res = Db::name("admins")->where($data)->find();
    //dump($res)
    if (!$res) {
        $this->error("帐号密码错误");
    }
    else {
        //dump($res);
        if(isset($_POST['rm'])){
            //勾选remember me
            setcookie("adminid",$res["adminid"],time()+(3600*24*30));
            setcookie("password",$res["password"],time()+(3600*24*30));
            setcookie("adminname",$res["adminname"],time()+(3600*24*30));

        }
//            dump($res);exit;
        Session::set("adminid", $res["adminid"]);
        Session::set("adminname", $res["adminname"]);
        Session::set("password", $res["password"]);
        $this->success('登录成功', 'index/index2');
    }

}
    public function index()
    {
        return $this->fetch();
    }
}
?>